﻿#region Imports
using System;
using CommonUtilities.Extensions;
#endregion

namespace CommonUtilities.Attributes
{
    /// <summary>
    /// Specifies mapping field when importing data
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    public sealed class DataImportMapAttribute : Attribute
    {
        #region Declaration
        /// <summary>
        /// Default property name
        /// </summary>
        public static readonly string DefaultPropertyName = "ImportName";

        /// <summary>
        /// Specifies the default instance for the <code>CommonUtilities.Attributes.DataImportMapAttribute</code>
        /// </summary>
        public static readonly DataImportMapAttribute Default = new DataImportMapAttribute("ImportName cannot be blank."); // RKD indecisive
        #endregion

        #region Properties
        /// <summary>
        /// Mapping field when importing data
        /// </summary>
        public string ImportName { get; private set; }
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new default instance of <code>CommonUtilities.Attributes.DataImportMapAttribute</code>
        /// </summary>
        internal DataImportMapAttribute()
            : base()
        {

        }

        /// <summary>
        /// Initializes a new instance of <code>CommonUtilities.Attributes.DataImportMapAttribute</code>
        /// with the specified mapping field &quot;<paramref name="importName"/>&quot; when importing data
        /// </summary>
        /// <param name="importName">Mapping field when importing data</param>
        public DataImportMapAttribute(string importName)
            : this()
        {
            if (importName.IsNullOrEmpty()) throw new InvalidOperationException("ImportName cannot be blank.");
            else
                ImportName = importName;
        }
        #endregion

        #region Methods
        public override bool Equals(object obj)
        {
            return this.ImportName == ((DataImportMapAttribute)obj).ImportName;
        }

        /// <summary>
        /// Determines if this attribute is the default instance
        /// </summary>
        /// <returns>TRUE if the attribute is the default instance for this attribute class;
        /// <para>otherwise, FALSE</para></returns>
        public override bool IsDefaultAttribute()
        {
            return this.ImportName == Default.ImportName;
        }
        #endregion
    }
}
